package main

import (
	"clientDemo/ui/fyne_ui/widget/custom"
	"fmt"
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/layout"
	"fyne.io/fyne/v2/widget"
)

func main() {
	myApp := app.New()
	myWindow := myApp.NewWindow("TabContainer 控件")
	var split *container.Split

	split = container.NewHSplit(
		widget.NewLabel("你好"),
		container.NewAppTabs(
			loadEditorTab(),
			loadInformationTab(),
		),
	)
	split.SetOffset(0.90)
	myWindow.SetContent(split)
	myWindow.Resize(fyne.NewSize(800, 400))
	myWindow.ShowAndRun()
}
func loadInformationTab() *container.TabItem {
	widthLabel := widget.NewLabel("Width: ")
	heightLabel := widget.NewLabel("Height: ")
	return container.NewTabItem("Information", container.NewScroll(
		container.NewVBox(
			widthLabel,
			heightLabel,
		),
	))
}

type editingSlider struct {
	widget.Slider
	dragEndFunc func(float64)
}

func (e *editingSlider) DragEnd() {
	e.dragEndFunc(e.Value)
}

//func newEditingSlider(min, max float64) *custom.editingSlider {
//	return custom.NewEditingSlider(min, max, func(f float64) {})
//	//editSlider := &editingSlider{}
//	//editSlider.Max = max
//	//editSlider.Min = min
//	//editSlider.ExtendBaseWidget(editSlider)
//	//return editSlider
//}
//func newEditingOption(infoText string, slider *editingSlider, defaultValue float64) *fyne.Container {
//	data := binding.BindFloat(&defaultValue)
//	text := widget.NewLabel(infoText)
//	value := widget.NewLabelWithData(binding.FloatToStringWithFormat(data, "%.0f"))
//	slider.Bind(data)
//	slider.Step = 1
//
//	return container.NewVBox(
//		container.NewHBox(
//			text,
//			layout.NewSpacer(),
//			value,
//		),
//		slider,
//	)
//}

// loadEditorTab returns the editor tab
func loadEditorTab() *container.TabItem {

	editColorBalanceR := custom.NewEditingOptionWithSlider("Red: ", -100, 500, 0, nil)
	editSepia := custom.NewEditingOptionWithSlider("Sepia: ", 0, 100, 0, func(f float64) {
		fmt.Println("+++++++++++++++++++++++++")
	})

	editBlur := custom.NewEditingOptionWithSlider("Blur: ", 0, 100, 0, nil)

	rotate90Btn := widget.NewButton("Rotate 90°", func() {})
	resizeBtn := widget.NewButton("Resize", func() {
	})

	moreEvilNinjas := []string{".aac", ".aiff", ".avi", ".bmp", ".c", ".cpp", ".csv", ".dat", ".dmg", ".dll", ".dng", ".doc", ".docx", ".eps", ".exe", ".flac", ".gif", ".h", ".html", ".ics", ".iso", ".java", ".jpeg", ".jpg", ".json", ".key", ".log", ".m4a", ".mp3", ".mp4", ".mpg", ".odt", ".otf", ".pdf", ".png", ".ppt", ".pptx", ".psd", ".py", ".rar", ".raw", ".rtf", ".svg", ".tar", ".tex", ".tga", ".tif", ".tiff", ".ts", ".txt", ".wav", ".webm", ".wmv", ".xls", ".xlsx", ".xml", ".yaml", ".zip"}
	folder_type := widget.NewSelectEntry(moreEvilNinjas)
	folder_type.SetPlaceHolder("Enter file type (ex .jpg)")
	folder_name := widget.NewEntry()
	folder_name.SetPlaceHolder("Enter folder name")
	folder_type.OnChanged = func(s string) {
		fmt.Println("--------------------------")
	}
	folder_name.OnChanged = func(s string) {
		fmt.Println("+++++++++++++++++++++++++")
	}
	// create grid
	one_folder := container.New(layout.NewGridLayout(2), folder_type, folder_name)
	one_folder2 := container.New(layout.NewGridLayout(3), widget.NewLabel("你好1"), widget.NewLabel("你好1"), widget.NewEntry())
	grid := container.New(layout.NewGridLayout(1), one_folder, one_folder2)
	return container.NewTabItem("Editor", container.NewScroll(
		container.NewVBox(
			widget.NewAccordion(
				widget.NewAccordionItem(
					"General",
					container.NewVBox(
						editSepia,
						editBlur,
					),
				),
				widget.NewAccordionItem(
					"General1",
					container.NewVBox(
						grid,
					),
				),
				widget.NewAccordionItem(
					"Color Balance",
					container.NewVBox(
						editColorBalanceR,
					),
				),
				widget.NewAccordionItem(
					"Transform",
					container.NewVBox(
						rotate90Btn,
						resizeBtn,
					),
				),
			),
			layout.NewSpacer(),
		)))
}
